<template>
  <header class="pubg-header">
    <div class="header-top">
      <div class="container">
        <div class="logo-area">
          <img src="/src/assets/pubg-images/pubg-logo.svg" alt="和平精英" class="logo-icon">
          <h1 class="logo-text">和平精英攻略中心</h1>
        </div>
        <div class="nav-links">
          <router-link to="/" class="nav-link active">首页</router-link>
          <router-link to="/weapons" class="nav-link">武器攻略</router-link>
          <router-link to="/maps" class="nav-link">地图解析</router-link>
          <router-link to="/tactics" class="nav-link">战术技巧</router-link>
          <router-link to="/tournaments" class="nav-link">赛事资讯</router-link>
          <router-link to="/videos" class="nav-link">视频教程</router-link>
          
          <!-- 未登录状态 -->
          <template v-if="!currentUser">
            <router-link to="/login" class="nav-link">登录</router-link>
            <router-link to="/register" class="nav-link">注册</router-link>
          </template>
          
          <!-- 已登录状态 -->
          <template v-else>
            <div class="user-menu">
              <div class="user-info">
                <span class="username">{{ currentUser.username }}</span>
                <div class="dropdown-menu">
                  <router-link to="/profile" class="dropdown-item">个人资料</router-link>
                  <router-link to="/membership" class="dropdown-item membership-link">会员充值</router-link>
                  <button @click="handleLogout" class="dropdown-item logout-btn">退出登录</button>
                </div>
              </div>
            </div>
          </template>
        </div>
      </div>
    </div>
  </header>
</template>

<script setup>
import { RouterLink } from 'vue-router'
import { inject } from 'vue'

// 注入全局用户状态和方法
const currentUser = inject('currentUser', null)
const handleLogout = inject('handleLogout')
</script>

<style scoped>
.pubg-header {
  background: var(--color-background);
  border-bottom: 3px solid var(--color-pubg-primary);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.08);
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: all 0.3s ease;
}

.pubg-header.scrolled {
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.12);
  padding-bottom: 0.5rem;
}

.header-top {
  padding: 1rem 0;
  transition: padding 0.3s ease;
}

.pubg-header.scrolled .header-top {
  padding: 0.75rem 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.3s ease;
}

.logo-area:hover {
  transform: scale(1.02);
}

.logo-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(240, 103, 62, 0.3);
  transition: all 0.3s ease;
  animation: pulse 2s infinite;
}

.logo-icon:hover {
  transform: rotate(5deg) scale(1.05);
  box-shadow: 0 6px 20px rgba(240, 103, 62, 0.4);
}

.logo-text {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0;
  color: var(--color-pubg-primary);
  text-transform: uppercase;
  letter-spacing: -0.5px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  position: relative;
}

.nav-link {
  color: var(--color-text);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 0;
  position: relative;
  transition: all 0.3s ease;
  overflow: hidden;
}

.nav-link::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: -100%;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--color-pubg-primary), transparent);
  transition: left 0.6s ease;
}

.nav-link:hover {
  color: var(--color-pubg-primary);
  transform: translateY(-2px);
}

.nav-link:hover::before {
  left: 100%;
}

.nav-link.active {
  color: var(--color-pubg-primary);
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background-color: var(--color-pubg-primary);
  border-radius: 3px;
  box-shadow: 0 0 10px rgba(240, 103, 62, 0.5);
}

/* 用户菜单样式 */
.user-menu {
  position: relative;
  margin-left: 1rem;
}

.user-info {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-text);
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  transition: all 0.3s ease;
  background: var(--color-background-soft);
  border: 1px solid var(--color-border);
}

.user-info::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--color-pubg-primary-light), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.user-info:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  border-color: var(--color-pubg-primary-light);
}

.user-info:hover::before {
  opacity: 0.2;
}

.username {
  font-weight: 600;
  position: relative;
  z-index: 1;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background-color: var(--color-background);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  margin-top: 0.5rem;
  min-width: 160px;
  z-index: 1000;
  display: none;
  border: 1px solid var(--color-border);
  animation: slideInRight 0.3s ease-out;
  overflow: hidden;
}

.user-info:hover .dropdown-menu {
  display: block;
}

.dropdown-item {
  padding: 0.85rem 1.25rem;
  text-decoration: none;
  color: var(--color-text);
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  box-sizing: border-box;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.dropdown-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--color-pubg-primary);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
}

.dropdown-item:hover {
  background-color: var(--color-background-soft);
  padding-left: 1.4rem;
}

.dropdown-item:hover::before {
  transform: translateX(0);
}

.logout-btn {
  color: var(--color-pubg-primary);
  font-weight: 600;
}

.logout-btn:hover {
  background-color: rgba(240, 103, 62, 0.1);
}

.membership-link {
  color: #f59e0b;
  font-weight: 600;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.05), transparent);
}

.membership-link::before {
  background: #f59e0b;
}

.membership-link:hover {
  background-color: rgba(245, 158, 11, 0.1);
}

/* 登录注册按钮特殊样式 */
.nav-links .router-link:last-child:nth-child(5),
.nav-links .router-link:nth-last-child(2):nth-child(4) {
  background: linear-gradient(135deg, var(--color-pubg-primary), var(--color-pubg-primary-dark));
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 25px;
  font-weight: 600;
  box-shadow: 0 4px 15px rgba(240, 103, 62, 0.3);
  transition: all 0.3s ease;
  margin-left: 0.5rem;
}

.nav-links .router-link:last-child:nth-child(5):hover,
.nav-links .router-link:nth-last-child(2):nth-child(4):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(240, 103, 62, 0.4);
}

.nav-links .router-link:nth-last-child(2):nth-child(4) {
  background: transparent;
  color: var(--color-pubg-primary);
  border: 2px solid var(--color-pubg-primary);
  box-shadow: none;
}

.nav-links .router-link:nth-last-child(2):nth-child(4):hover {
  background: var(--color-pubg-primary);
  color: white;
  box-shadow: 0 4px 15px rgba(240, 103, 62, 0.3);
}

@media (max-width: 768px) {
  .container {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  
  .nav-links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
  }
  
  .logo-text {
    font-size: 1.3rem;
  }
  
  .logo-icon {
    width: 40px;
    height: 40px;
  }
  
  .nav-link {
    font-size: 0.9rem;
    padding: 0.5rem 0;
  }
  
  .dropdown-menu {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }
  
  .nav-links .router-link:last-child:nth-child(5),
  .nav-links .router-link:nth-last-child(2):nth-child(4) {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .nav-links {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .user-menu {
    margin-left: 0;
    margin-top: 0.5rem;
  }
}
</style>